<?php
/**
* @package class.userprofile.php
* The user profile interactions class file
*
* @author Nitesh Apte
* @copyright 2010
* @version 1.0
* @access public
* @license GPL
*/

include 'class.mysqldb.php';
class UserProfile extends MySqlDB
{
	/**
	* Private variables for making query with database
	*/
	private $Email;
	private $Pass;
	private $query;

	/**
	* _userLogin()
	* User login process
	*
	* @param $admin_email string
	* @param $admin_pass string
	* @return $this object Boolean
	*/
	public function _userLogin($u_email, $u_pass)
	{
		$this->Email = $u_email;
		$this->Pass = $u_pass;
		
		try {
			$this->query = "SELECT id,  name, email_id, access_lvl FROM users WHERE email_id='" . $this->Email . "' " . "AND passwd='" . $this->Pass. "' " . "AND access_lvl=1";
			parent::_executeSql($this->query);
			parent::_fetchRows();
			if(count($this->rows)>0)
			{
				session_start();
				$_SESSION['user_id'] = md5($this->rows['id']);
				$_SESSION['name'] = $this->rows['name'];
				$_SESSION['email'] = $this->rows['email_id'];
				$_SESSION['access_lvl'] = $this->rows['access_lvl'];
				return $this;
			}
			else
			{
				//header("Location: welcome.php");
				//exit(0);
			}
		}
		catch(Exception $e) {
			trigger_error($e->getMessage());
		}
	}

	/**
	* _userLogout()
	* User logout process
	*
	* @param none
	* @return none
	*/
	public static function _userLogout()
	{
		try {
			session_start();
			session_unset();
			session_destroy();
			header('Location: index.php');
			exit();
		}
		catch(Exception $e) {
			trigger_error($e->getMessage());
		}
	}
}
?>